package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

//增强for循环/新循环:
public class NewForDemo {
    public static void main(String[] args) {
        String[] array = {"one","two","three","four","five"};
        for (int i = 0; i <array.length; i++) {
            System.out.println(array[i]);
        }
        for (String str : array){
            System.out.println(str);
        }

    /*for(元素类型  变量名  : 集合或数组){
            循环体;
      }
    */

        Collection<String> c = new ArrayList();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        Iterator it = c.iterator();
        while (it.hasNext()){
            String str = (String) it.next();
            System.out.println(str);
        }

        for (Object s : c){//s 代表集合中的每个元素
            String str = (String) s ;
            System.out.println(str);
        }
    }
}
